package org.swift.commons.xml.vtd;

import com.ximpleware.AutoPilot;
import com.ximpleware.NavException;
import com.ximpleware.XPathEvalException;
import com.ximpleware.XPathParseException;

public class MemoryAutomaticPilot implements AutomaticPilot {

	private final AutoPilot autoPilot;
	
	public MemoryAutomaticPilot(AutoPilot autoPilot) {
		this.autoPilot = autoPilot;
	}

	@Override
	public void declareXPathNameSpace(String key, String value) {
		this.autoPilot.declareXPathNameSpace(key, value);
	}

	@Override
	public int evalXPath() throws XPathEvaluationException, NavigationException {
		try {
			return this.autoPilot.evalXPath();
		} catch (XPathEvalException e) {
			throw new XPathEvaluationException(e);
		} catch (NavException e) {
			throw new NavigationException(e);
		}
	}

	@Override
	public String evalXPathToString() {
		return this.autoPilot.evalXPathToString();
	}

	@Override
	public void selectXPath(String xpath) throws XPathParserException {
		try {
			this.autoPilot.selectXPath(xpath);
		} catch (XPathParseException e) {
			throw new XPathParserException(e);
		}
	}

}
